//+---------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation, 2005
//
// File: BaseExceptionContext.cs
//
// Contents: A structure that provides a flattened error message
//
// Created by: adamland 2/18/2005
//
//----------------------------------------------------------------------------

using System;
using System.Text;
using System.Globalization;

namespace Microsoft.Reputation.Services
{
    public class BaseExceptionContext
    {
        private string m_objectString = string.Empty;
        private string m_operationString = string.Empty;
        private string m_errorString = string.Empty;

        private BaseExceptionContext()
        {
        }

        public BaseExceptionContext(string errorString)
        {
            m_errorString = errorString;
        }

        public BaseExceptionContext(string errorString, string operationString)
        {
            m_errorString = errorString;
            m_operationString = operationString;
        }

        public BaseExceptionContext(string errorString, string operationString, string objectString)
        {
            m_errorString = errorString;
            m_operationString = operationString;
            m_objectString = objectString;
        }

        public virtual string BuildMessage()
        {
            //
            // Some backend error strings contain one or two newlines which make our messages
            // look ugly. Replace them with spaces.
            //

            m_errorString = m_errorString.Replace("\r\n\r\n", "  ");
            m_errorString = m_errorString.Replace("\r\n", "  ");
        
            return String.Format(
                CultureInfo.CurrentCulture,
                CommonStrings.ErrorMessageFormat_Complete,
                m_objectString,
                m_operationString,
                m_errorString);
        }

        public bool HasObjectString
        {
            get
            {
                return !string.IsNullOrEmpty(m_objectString);
            }
        }

        public bool HasOperationString
        {
            get
            {
                return !string.IsNullOrEmpty(m_operationString);
            }
        }

        public bool HasErrorString
        {
            get
            {
                return !string.IsNullOrEmpty(m_errorString);
            }
        }

        public string ObjectString
        {
            get
            {
                return m_objectString;
            }
            set
            {
                m_objectString = value;
            }
        }

        public string OperationString
        {
            get
            {
                return m_operationString;
            }
            set
            {
                m_operationString = value;
            }
        }

        public string ErrorString
        {
            get
            {
                return m_errorString;
            }
            set
            {
                m_errorString = value;
            }
        }
    }
}
